<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>
    Laravel 简短学习 just write the code in the PHP way |
    
    无敌小笼包</title>
  
    <link rel="shortcut icon" href="/favicon.png">
  
  <link rel="stylesheet" href="/css/style.css">
  
    <link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">
  
  <script src="/js/pace.min.js"></script>
</head>

<body>
<main class="content">
  <section class="outer">
  <article id="post-learnLaravel" class="article article-type-post" itemscope itemprop="blogPost">

  <div class="article-inner">
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Laravel 简短学习 just write the code in the PHP way
    </h1>
  

      </header>
    

    
      <div class="article-meta">
        <a href="/2017/05/31/learnLaravel/" class="article-date">
  <time datetime="2017-05-31T05:58:41.000Z" itemprop="datePublished">2017-05-31</time>
</a>
        
  <div class="article-category">
    <a class="article-category-link" href="/categories/Laravel/">Laravel</a>
  </div>

      </div>
    

    <div class="article-entry" itemprop="articleBody">
      
      
      
        <p>　　<strong> 自用笔记：</strong>本文属于自用笔记，不做详解，仅供参考。</p>
<a id="more"></a>
<h3 id="artisan"><a href="#artisan" class="headerlink" title="artisan"></a><a href="https://docs.golaravel.com/docs/5.1/artisan/" target="_blank" rel="noopener">artisan</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">英  /,ɑːtɪ&apos;zæn; &apos;ɑːtɪzæn/</div><div class="line">美  /&apos;ɑrtəzn/</div><div class="line">n. 工匠，技工</div></pre></td></tr></table></figure>
<h3 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h3><hr>
<p><code>Artisan</code> 是 <code>Laravel</code> 的命令行接口的名称，它提供了许多实用的命令来帮助你开发 <code>Laravel</code> 应用，它由强大的 <code>Symfony Console</code> 组件所驱动。</p>
<p>可以使用 <code>list</code> 命令来列出所有可用的 <code>Artisan</code> 命令：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">php artisan <span class="keyword">list</span></div></pre></td></tr></table></figure>
<blockquote>
<p>Available commands:</p>
</blockquote>
<table>
<thead>
<tr>
<th>命令</th>
<th>explain</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>clear-compiled</td>
<td>Remove the compiled class file</td>
<td>清除编译后的类文件</td>
</tr>
<tr>
<td>down</td>
<td>Put the application into maintenance mode</td>
<td>使应用程序进入维修模式</td>
</tr>
<tr>
<td>  env</td>
<td>Display the current framework environment</td>
<td>显示当前框架环境</td>
</tr>
<tr>
<td>  help</td>
<td>Displays help for a command</td>
<td>显示命令行的帮助</td>
</tr>
<tr>
<td>  list</td>
<td>Lists commands</td>
<td>列出命令</td>
</tr>
<tr>
<td>  migrate</td>
<td>Run the database migrations</td>
<td>运行数据库迁移</td>
</tr>
<tr>
<td>  optimize</td>
<td>Optimize the framework for better performance</td>
<td>为了更好的框架去优化性能</td>
</tr>
<tr>
<td>  serve</td>
<td>Serve the application on the PHP development server</td>
<td>在php开发服务器中服务这个应用</td>
</tr>
<tr>
<td>  tinker</td>
<td>Interact with your application</td>
<td>在你的应用中交互</td>
</tr>
<tr>
<td>  up</td>
<td>Bring the application out of maintenance mode</td>
<td>退出应用程序的维护模式</td>
</tr>
</tbody>
</table>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div></pre></td><td class="code"><pre><div class="line">app</div><div class="line"> app:name            Set the application namespace 设置应用程序命名空间</div><div class="line">auth</div><div class="line"> auth:clear-resets   Flush expired password reset tokens 清除过期的密码重置密钥</div><div class="line">cache</div><div class="line"> cache:clear         Flush the application cache 清除应用程序缓存</div><div class="line"> cache:table         Create a migration for the cache database table 创建一个缓存数据库表的迁移</div><div class="line">config</div><div class="line"> config:cache        Create a cache file for faster configuration loading 创建一个加载配置的缓存文件</div><div class="line"> config:clear        Remove the configuration cache file 删除配置的缓存文件</div><div class="line">db</div><div class="line"> db:seed             Seed the database with records 发送数据库的详细记录</div><div class="line">event</div><div class="line"> event:generate      Generate the missing events and listeners based on  registration  在记录上生成错过的事件和基础程序</div><div class="line">key</div><div class="line"> key:generate        Set the application key 设置程序密钥</div><div class="line">make</div><div class="line"> make:auth           Scaffold basic login and registration views and routes</div><div class="line"> make:console        Create a new Artisan command 生成一个Artisan命令</div><div class="line"> make:controller     Create a new controller class 生成一个资源控制类</div><div class="line"> make:event          Create a new event class  生成一个事件类</div><div class="line"> make:job            Create a new job class</div><div class="line"> make:listener       Create a new event listener class</div><div class="line"> make:middleware     Create a new middleware class 生成一个中间件</div><div class="line"> make:migration      Create a new migration file 生成一个迁移文件</div><div class="line"> make:model          Create a new Eloquent model class 生成一个Eloquent 模型类</div><div class="line"> make:policy         Create a new policy class</div><div class="line"> make:provider       Create a new service provider class 生成一个服务提供商的类</div><div class="line"> make:request        Create a new form request class 生成一个表单消息类</div><div class="line"> make:seeder         Create a new seeder class</div><div class="line"> make:test           Create a new test class</div><div class="line">migrate</div><div class="line"> migrate:install     Create the migration repository 创建一个迁移库文件</div><div class="line"> migrate:refresh     Reset and re-run all migrations 复位并重新运行所有的迁移</div><div class="line"> migrate:reset       Rollback all database migrations 回滚全部数据库迁移</div><div class="line"> migrate:rollback    Rollback the last database migration 回滚最后一个数据库迁移</div><div class="line"> migrate:status      Show the status of each migration 显示列表的迁移 上/下</div><div class="line">queue</div><div class="line"> queue:failed        List all of the failed queue jobs 列出全部失败的队列工作</div><div class="line"> queue:failed-table  Create a migration for the failed queue jobs database table     创建一个迁移的失败的队列数据库工作表</div><div class="line"> queue:flush         Flush all of the failed queue jobs                 清除全部失败的队列工作</div><div class="line"> queue:forget        Delete a failed queue job 删除一个失败的队列工作</div><div class="line"> queue:listen        Listen to a given queue 监听一个确定的队列工作</div><div class="line"> queue:restart       Restart queue worker daemons after their current job 重启现在正在运行的所有队列工作</div><div class="line"> queue:retry         Retry a failed queue job 重试一个失败的队列工作</div><div class="line"> queue:table         Create a migration for the queue jobs database table 创建一个迁移的队列数据库工作表</div><div class="line"> queue:work          Process the next job on a queue 进行下一个队列任务</div><div class="line">route</div><div class="line"> route:cache         Create a route cache file for faster route registration 为了更快的路由登记，创建一个路由缓存文件</div><div class="line"> route:clear         Remove the route cache file 清除路由缓存文件</div><div class="line"> route:list          List all registered routes  列出全部的注册路由</div><div class="line">schedule</div><div class="line"> schedule:run        Run the scheduled commands 运行预定命令</div><div class="line">session</div><div class="line"> session:table       Create a migration for the session database table                 创建一个迁移的SESSION数据库工作表</div><div class="line">vendor</div><div class="line"> vendor:publish      Publish any publishable assets from vendor packages 发表一些可以发布的有用的资源来自提供商的插件包</div><div class="line">view</div><div class="line"> view:clear          Clear all compiled view files</div></pre></td></tr></table></figure>
<p>每个命令也包含了「帮助」界面，它会显示并概述命令可使的参数及选项。只要在命令前面加上 help 即可显示帮助界面：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">php artisan help migrate</div></pre></td></tr></table></figure>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">php artisan make:auth</div></pre></td></tr></table></figure>
<h3 id="编写命令"><a href="#编写命令" class="headerlink" title="编写命令"></a>编写命令</h3><hr>
<p>除了使用 <code>Artisan</code> 本身所提供的命令之外，<code>Laravel</code> 也允许你自定义 <code>Artisan</code> 命令。</p>
<p>自定义命令默认存储在 <code>app/Console/Commands</code> 目录中，当然，只要在 <code>composer.json</code> 文件中的配置了自动加载，你可以自由选择想要放置的地方。</p>
<p>若要创建新的命令，你可以使用 <code>make:console Artisan</code>命令生成命令文件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">php artisan make:console SendEmails</div></pre></td></tr></table></figure>
<p>上面的这个命令会生成 <code>app/Console/Commands/SendEmails.php</code> 类，–command 参数可以用来指定调用名称：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">php artisan make:console SendEmails --command=emails:send</div></pre></td></tr></table></figure>
<h3 id="命令结构"><a href="#命令结构" class="headerlink" title="命令结构"></a>命令结构</h3><hr>
<p>一旦生成这个命令，应先填写类的 <code>signature</code> 和 <code>description</code> 这两个属性，它们会被显示在  <code>list</code> 界面中。<br>命令运行时 <code>handle</code> 方法会被调用，请将程序逻辑放置在此方法中。<br>接下来讲解一个发送邮件的例子。<br>为了更好的代码重用性，还有可读性，建议把处理业务逻辑的代码抽到一个功能类里。<br><code>Command</code> 类构造器允许注入需要的依赖，<code>Laravel</code> 的 服务容器 将会自动把功能类 <code>DripEmailer</code> 解析到构造器中</p>
<h3 id="Route"><a href="#Route" class="headerlink" title="Route"></a><a href="http://d.laravel-china.org/docs/5.1/routing" target="_blank" rel="noopener">Route</a></h3><hr>
<p>你可以在 <code>app/Http/routes.php</code> 文件中定义应用程序的大多数路由，该文件将会被 <code>App\Providers\RouteServiceProvider</code> 类加载。最基本的 <code>Laravel</code> 路由仅接受 <code>URI</code> 和一个闭包</p>
<h3 id="view-Blade"><a href="#view-Blade" class="headerlink" title="view-Blade"></a><a href="http://d.laravel-china.org/docs/5.1/blade" target="_blank" rel="noopener">view-Blade</a></h3><hr>
<p><code>Blade</code> 是 <code>Laravel</code> 所提供的一个简单且强大的模板引擎。相较于其它知名的 <code>PHP</code> 模板引擎，<code>Blade</code> 并不会限制你必须得在视图中使用 <code>PHP</code> 代码。所有 <code>Blade</code> 视图都会被编译缓存成普通的 PHP 代码，一直到它们被更改为止。这代表 <code>Blade</code> 基本不会对你的应用程序生成负担。</p>
<p><code>Blade</code> 视图文件使用 <code>.blade.php</code> 做为扩展名，通常保存于 <code>resources/views</code> 文件夹内。</p>
<p><code>@extends(&#39;layouts.app&#39;)</code></p>
<p>这表示此视图的基视图是 <code>resources/views/layouts/app.blade.php</code> 。这个函数还隐含了一个小知识：在使用名称查找视图的时候，可以使用 <code>.</code> 来代替 <code>/</code> 或 <code>\</code>.</p>
<p><code>@Section(&#39;content&#39;) ... @endsection</code><br>这两个标识符之前的代码，会被放到基视图的 <code>@yield(&#39;content&#39;)</code> 中进行输出。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://blog.mango16.cc/2017/05/31/learnLaravel/" data-id="cjrbtw1y0000t6d8hrvnfny1g"
         class="article-share-link">分享</a>
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/phper/">phper</a></li></ul>

    </footer>

  </div>

  
    
  <nav class="article-nav">
    
      <a href="/2017/06/07/OpenSource/" class="article-nav-link">
        <strong class="article-nav-caption">前一篇</strong>
        <div class="article-nav-title">
          
            开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
          
        </div>
      </a>
    
    
      <a href="/2017/04/12/Guzzle/" class="article-nav-link">
        <strong class="article-nav-caption">后一篇</strong>
        <div class="article-nav-title">利用Guzzle刷豆瓣热评引发的联想</div>
      </a>
    
  </nav>


  

  
    
  <div class="gitalk" id="gitalk-container"></div>
  <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
  <script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
  <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
  <script type="text/javascript">
      var gitalk = new Gitalk({
        clientID: 'caba8826a61790936307',
        clientSecret: '09a15037dcab30d9adf35a53ec6961939169f797',
        repo: 'm9rco.github.io',
        owner: 'm9rco',
        admin: ['m9rco'],
        // id: location.pathname,      // Ensure uniqueness and length less than 50
        id: md5(location.pathname),
        distractionFreeMode: false  // Facebook-like distraction free mode
      })

  gitalk.render('gitalk-container')
  </script>

  

</article>



</section>
  <footer class="footer">
  
  <div class="outer">
    <ul class="list-inline">
      <li>&copy; 2019 无敌小笼包</li>
      <i class="pulse"></i>
    </ul>
  </div>
</footer>

</main>
<aside class="sidebar">
  <button class="navbar-toggle"></button>

<nav class="navbar">
  
    <div class="logo">
      <a href="/"><img src="/images/hexo.svg" alt="无敌小笼包"></a>
    </div>
  
  <ul class="nav nav-main">
    
      <li class="nav-item">
        <a class="nav-item-link" href="/">主页</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/archives">归档</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/gallery">相册</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/nagging">叽咕</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/about">关于</a>
      </li>
    
    <li class="nav-item">
      <a class="nav-item-link nav-item-search" title="Search">
        <i class="fe fe-search"></i>
        搜索
      </a>
    </li>
  </ul>
</nav>

<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
        <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
          <i class="fe fe-feed"></i>
        </a>
      
    </li>
  </ul>
</nav>

<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
</aside>
  <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/lazyload.min.js"></script>


  <script src="/fancybox/jquery.fancybox.min.js"></script>



  <script src="/js/search.js"></script>


<script src="/js/ocean.js"></script>

</body>
</html>